<template>
<view>
	<view class="list">
	  <view @click='jumpTo(item,index)' v-for="(item,index) in keys" :key="index">{{item}}</view>
	</view>
			
	<scroll-view scroll-y="true" :scroll-into-view="intoindex" 
	class="position gochooseAbank">
	    <view class='new_city'>
	        <view class='new_city_title'>热门城市</view>
	        <view class='new_city_box'>
	            <text class='new_city_text' v-for='(item,index) in newcity' :key='this' data-types='new' @click='cityTap(item)'>{{item}}</text>
	        </view>
	    </view>
	
	    <view class='city_list_box'>
	        <block v-for='(item,index) in citylist' :key="index">
	            <view class='city_first_letter' :id='"text"+item.letter' >{{item.letter}}</view>
	            <text class='city_name' v-for='(iitem,iindex) in item.list' :key="iindex" 
				@click='cityTap(iitem)'>{{iitem}}</text>
	        </block>
	    </view>
	</scroll-view>
</view>
</template>
<script>
import request from '@/util/request.js'	
import Citys from './city';
export default {
	data() {
		return {
			keys:['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','P','Q','S','T','U','W','X','Y','Z'],
			citylist:Citys,
			intoindex:'',
			//下面是热门城市数据，模拟数据
			newcity: ['全部','北京', '上海', '广州', '深圳', '重庆', '天津','成都','杭州'],				
		}
	},
	onLoad:function(){
		
	},
	methods: {
		jumpTo:function(item,index){
			this.$nextTick(()=> {
				this.intoindex = 'text' + item
			});
		},
		cityTap:function(e){
			var pages = getCurrentPages();
			var currPage = pages[pages.length - 1]; //当前页面
			var prevPage = pages[pages.length - 2]; //上一个页面
			
			if(prevPage.route == 'pages/user/info/company'){
				prevPage.$vm.form.city = e
				uni.navigateBack();
				return;
			}
			if(prevPage.route == 'pages/user/info/personal'){
				prevPage.$vm.form.city = e
				uni.navigateBack();
				return;
			}
			if(prevPage.route == 'pages/login/personal'){
				prevPage.$vm.form.city = e
				uni.setStorageSync('pForm',prevPage.$vm.form)
				prevPage.$vm.$forceUpdate();
				uni.navigateBack();
				return;
			}
			if(prevPage.route == 'pages/login/company'){
				//直接调用上一个页面的setData()方法，把数据存到上一个页面中去
				prevPage.$vm.form.city = e
				uni.setStorageSync('cForm',prevPage.$vm.form)
				prevPage.$vm.$forceUpdate();
				uni.navigateBack();
				return;
			}
			prevPage.$vm.form.city = e
			uni.navigateBack();
		},
	}
}
</script>
<style scoped>
	@import url("./css/index.css");
</style>